package pluginFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import pluginInterfaces.IPluginComposition;

/**
 * Class that is used to load and retrieve Composition plugins.
 * 
 * @author Andy Cullache
 */
public class CompositionPluginFactory  {

	/**
	 * Gets all the objects "IPluginComposition" found in the classpath. 
	 * For this you must first load the plugins from the "plugins / composition".
	 * @return      List of plugins found and charged to the classpath.
	 */
	public static List<IPluginComposition> retrieveAll() {
		List<IPluginComposition> iPluginList = new ArrayList<IPluginComposition>();			    
		try {
			if (PluginsCharger.Charger("plugins/composition"))
			{
				ServiceLoader<IPluginComposition> sl = ServiceLoader.load(IPluginComposition.class);
				sl.reload();
				for(IPluginComposition pl : sl)
				{
					iPluginList.add(pl);
				}
			}
		} catch (PluginFactoryException e) {
			e.printStackTrace();
		}
	    return iPluginList;
	}

}
